<?php namespace Modules\Shop\Http\Controllers;


class CatalogController extends Controller {

    public function getIndex()
    {

        global $_CFG, $ecs, $err, $smarty, $_LANG, $db, $charset;

        if (!\Tpl::is_cached('catalog.dwt')) {
            /* 取出所有分类 */
            $cat_list = cat_list(0, 0, false);

            foreach ($cat_list AS $key => $val) {
                if ($val['is_show'] == 0) {
                    unset($cat_list[ $key ]);
                }
            }


            assign_template();
            assign_dynamic('catalog');
            $position = assign_ur_here(0, $_LANG['catalog']);
            \Tpl::assign('page_title', $position['title']);   // 页面标题
            \Tpl::assign('ur_here', $position['ur_here']); // 当前位置

            \Tpl::assign('helps', get_shop_help()); // 网店帮助
            \Tpl::assign('cat_list', $cat_list);       // 分类列表
            \Tpl::assign('brand_list', get_brands());    // 所以品牌赋值
            \Tpl::assign('promotion_info', get_promotion_info());
        }

        \Tpl::display('catalog.dwt');

		return view('shop::index');
	}
	
}


/**
 * 计算指定分类的商品数量
 *
 * @access public
 * @param   integer $cat_id
 *
 * @return void
 */
/**
 * @param $cat_list
 * @param $cat_id
 * @return int
 */
function calculate_goods_num($cat_list, $cat_id)
{
    $goods_num = 0;

    foreach ($cat_list AS $cat) {
        if ($cat['parent_id'] == $cat_id && !empty($cat['goods_num'])) {
            $goods_num += $cat['goods_num'];
        }
    }

    return $goods_num;
}